<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Artifact extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'artifact';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];
    

    public function getAllArtifact($redis)
    {
        $data = $redis->get('artifact');
        if ($data) {
            return json_decode($data, true);
        }
        $data = $this->select();

        $data = collection($data)->toArray();
        // id => row
        $data = array_column($data, null, 'id');
        $redis->set('artifact', json_encode($data), 3600);
        return $data;    
    }


}
